package com.qiwx.pigeon.activity.produce;

import android.content.Intent;
import android.os.Bundle;
import android.text.TextUtils;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.qiwx.pigeon.R;
import com.qiwx.pigeon.Utils.MyToast;
import com.qiwx.pigeon.base.BaseMVPActivity;
import com.qiwx.pigeon.base.Constant;
import com.qiwx.pigeon.data.params.FertilizeParam;
import com.qiwx.pigeon.data.vo.CageStatusRecordBean;
import com.qiwx.pigeon.data.vo.FertilizeBean;
import com.qiwx.pigeon.data.vo.pageinfo.PageInfo;
import com.qiwx.pigeon.presenter.OperatePresenter;
import com.qiwx.pigeon.viewinterface.IOperateView;
import com.qiwx.pigeon.widget.AddLayEggOptionView;
import com.qiwx.pigeon.widget.ArrowView;

import java.lang.ref.WeakReference;
import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;

import static com.qiwx.pigeon.activity.common.SelectDateActivity.REQUEST_CODE_START;

/**
 * @description
 * @Author qiwx
 * @Date 2020-03-30 10:15
 * 补录下蛋日期
 **/
public class AddLayEggDateProduceActivity extends BaseMVPActivity<IOperateView, OperatePresenter> implements IOperateView {
    @BindView(R.id.title_content)
    TextView titleContent;
    @BindView(R.id.title_return)
    ArrowView titleReturn;
    @BindView(R.id.llTitle)
    LinearLayout llTitle;
    @BindView(R.id.edt_cage_number)
    EditText edtCageNumber;
    @BindView(R.id.txt_1)
    TextView txt1;
    @BindView(R.id.txt_start_date)
    TextView txtStartDate;
    @BindView(R.id.btn_opreation_ok)
    Button btnOpreationOk;
    @BindView(R.id.lin_cagenumber)
    LinearLayout linCagenumber;

    int c_number;
    int wh_id = 0;
    int wh_number = 0;
    @BindView(R.id.title_right)
    TextView titleRight;
    @BindView(R.id.add_lay_egg_options)
    AddLayEggOptionView addLayEggOptionView;


    @Override
    public int getLayoutId() {
        return R.layout.activity_add_layegg_date;
    }

    @Override
    public void initAfterOnCreate() {
        initView();
    }

    @Override
    public void onActivityResult(int requestCode, int resultCode, Intent data) {
        super.onActivityResult(requestCode, resultCode, data);
        switch (requestCode) {
            case REQUEST_CODE_START:
                if (data != null && !TextUtils.isEmpty(data.getStringExtra("car_Time_MSG"))) {
                    txtStartDate.setText(data.getStringExtra("car_Time_MSG"));
                }
                break;
        }
    }

    private void initView() {
//        rbShouj2.setChecked(false);
        // c_id = getIntent().getIntExtra(Constant.INTENT_C_ID, 0);
        c_number = getIntent().getIntExtra(Constant.INTENT_C_NUMBER, 0);
        wh_id = getIntent().getIntExtra(Constant.INTENT_WH_ID, 0);
        wh_number = getIntent().getIntExtra(Constant.INTENT_WH_NUMBER, 0);
        titleContent.setText("补录下蛋(" + wh_number + "号鸽仓)");
        titleReturn.changeArrowLeft();
//        String cageId = getIntent().getStringExtra("CageId");
        if (c_number > 0) {
            edtCageNumber.setText(c_number + "");
        }
    }

    //下蛋确认操作
    private void saveLayEgg() {
        int cageNumber = 0;
        try {
            cageNumber = Integer.valueOf(edtCageNumber.getText().toString());
        } catch (Exception e) {
            e.printStackTrace();
        }
        if (TextUtils.isEmpty(txtStartDate.getText().toString())) {
            MyToast.showLong("选择下蛋日期");
            return;
        }
        String txtStart = txtStartDate.getText().toString();
        String layEggDate = txtStart;
        // boolean isFudan=currentCheckId>0?true:false;
        FertilizeParam param = addLayEggOptionView.getBLParam();
        param.setWh_id(wh_id);
//        param.setC_id(c_id);
        param.setNumber(cageNumber);
        param.setLay_egg_date(layEggDate);
        mPresenter.saveLayEgg(param);
    }


    @OnClick({R.id.title_return, R.id.btn_opreation_ok, R.id.txt_start_date})
    public void onViewClicked(View view) {
        switch (view.getId()) {
            case R.id.title_return:
                finish();
                break;
            case R.id.btn_opreation_ok:
                saveLayEgg();
                break;
            case R.id.txt_start_date:
                selectStartValiDate("下蛋日期");
                break;
        }
    }


    @Override
    public OperatePresenter createPresenter() {
        return new OperatePresenter(new WeakReference<>(this));
    }

    @Override
    public void onCheckEggSuccess(PageInfo<FertilizeBean> list) {

    }

    @Override
    public void onQueryCateStatusRecordSuccess(List<CageStatusRecordBean> list) {

    }

    @Override
    public void onSaveLayEggSuccess(int c_id) {
        MyToast.showLong("操作成功");
        edtCageNumber.setText(null);

    }

    @Override
    public void onAddOperate(int type) {

    }

    @Override
    public void onFailed(String error) {

    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        // TODO: add setContentView(...) invocation
        ButterKnife.bind(this);
    }
}
